//
//  YYAlamofireProtocol.swift
//  YYProject
//
//  Created by 陆文宇 on 2017/8/29.
//  Copyright © 2017年 陆文宇. All rights reserved.
//

import Foundation

protocol YYAlamofireProtocol {
    
    func yy_analyzData(_ data: Any) -> [YYModel]?
    func yy_handlerData(_ data: [YYModel]?)
    func yy_requestFailure(errmsg: String) -> String?
    
}

extension YYAlamofireProtocol {
    
    func yy_requestData(url: String, parameters: [String: String]? = nil) {
        yy_post(url: url, parameters: parameters, success: { (data) in
            self.yy_handlerData(self.yy_analyzData(data!))
        }) { (error) in
            return self.yy_requestFailure(errmsg: error)
        }
    }
    
    func yy_unpack(_ value: Any?) -> String {
        return "\(value ?? "--")"
    }
    
}
